$(function() {
	
	var mailType = $('#mailType').val();

	//用户管理菜单Panel初始化
	$('#mailPanel').panel({
		border:false
	});
	
	//用户管理菜单Panel初始化
	$('#mailPanel2').panel({
		border:false
	});
	
	//菜单按钮初始化
	$('#delMailBtn').linkbutton({plain:true,iconCls:'icon-mail-remove'});
	$('#viewMailBtn').linkbutton({plain:true,iconCls:'icon-mail-open'});
	$('#closeMailBtn').linkbutton({plain:true,iconCls:'icon-close'});
	
	$('#close').linkbutton({plain:true,iconCls:'icon-cancel'});
	
	//添加窗口
	$('#mailWindow').window({
		title:'阅读邮件',
		closed:true,
		modal:true,
		closable:true,
		minimizable:false,
		maximizable:false,
		collapsible:false,
		resizable:false,
		iconCls:'icon-mail-open',
		width:650,
		height:500
	});	
	
	//初始化MailDateGrid
	$('#mailDataGrid').datagrid({
		url:'mailAjax!receive',
		nowrap: false,
		border:false,
		striped: true,
		collapsible:true,
		sortName: 'id',
		singleSelect:false,
		sortOrder: 'desc',
		remoteSort: false,
		pagination:true,
		idField:'id',
		columns:[[
		          {field:'ck', checkbox:true},
		          {field:'id',title:'编号',width:50},
		          {field:'sendName',title:'发件人',width:150},
		          {field:'title',title:'主题',width:500},
		          {field:'date',title:'日期',width:150}
		          ]]
		});

		var pager = $('#mailDataGrid').datagrid('getPager');
		$(pager).pagination({
			pageSize: 15,
			pageList: [15, 30, 50, 100],
			beforePageText: '第',
			afterPageText: '页    共 {pages} 页',
			displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
			onSelectPage:function(pageNumber, pageSize){
				$('#mailDataGrid').datagrid('options').url = 'mailAjax!receive?pageNo=' + pageNumber + '&pageSize='+ pageSize;
				$('#mailDataGrid').datagrid('reload', pageNumber);
			}
		});
	
	
});

function openMailWindow(type){
	
	if(type == 'view'){
		setValue();
	}

	$('#mailWindow').window('open');
}

function setValue(){
	var selectedRow = $('#mailDataGrid').datagrid('getSelected');
	$('#mailTitle').html(selectedRow.title);
	$('#mailSendName').html(selectedRow.sendName);
	$('#mailDate').html(selectedRow.date);
	$('#mailReceiveNames').html(selectedRow.receiveNames);
	$('#mailContent').html(selectedRow.content);
}

function closeWindow(){
	$('#mailWindow').window('close');
}